/**
 * @author zhaozhenjiang
 * json工具类
 * */

package test.com;

import java.io.IOException;

import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;

/**
 * GDK json工具类
 * */
final class jsonUtils {
	private static jsonUtils jutil = null;
	private final static Object lock_jutil = new Object();
	
	private jsonUtils(){}
	
	/**
	 * 双重锁定单例模式
	 * */
	public static jsonUtils getInstance(){
		if(jutil == null){
			synchronized (lock_jutil) {
				jutil = new jsonUtils();
			}
		}
		return jutil;
	}
	
	/**
	 * 将JAVA对象序列化为JSON字符串
	 * */
	public String serializeJson(Object obj) throws IOException{
		ObjectMapper objectMapper = new ObjectMapper();
		String _json = objectMapper.writeValueAsString(obj);
		return _json;
	}
	
	/**
	 * 将JSON字符串反序列化为JAVA对象
	 * */
	public <T> T deserializeJson(String json,Class<T> cla) 
		throws JsonParseException, JsonMappingException, IOException{
		ObjectMapper objectMapper = new ObjectMapper();
		return objectMapper.readValue(json, cla);
	}	

	@SuppressWarnings("unused")
	private class Decompile{
		
	}
}
